<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改活动信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-activity-edit" th:object="${businessActivity}">
            <input name="activityId" th:field="*{activityId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input id="activityName" name="activityName" th:field="*{activityName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">地点：</label>
                <div class="col-sm-8">
                    <input id="activityAddress" name="activityAddress" th:field="*{activityAddress}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">主办方：</label>
                <div class="col-sm-8">
                    <input id="activityOrganizer" name="activityOrganizer" th:field="*{activityOrganizer}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">负责人：</label>
                <div class="col-sm-8">
                    <input id="activityWorker" name="activityWorker" th:field="*{activityWorker}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input id="activityStartTime" name="activityStartTime" th:value="${#dates.format(businessActivity.activityStartTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input id="activityEndTime" name="activityEndTime" th:value="${#dates.format(businessActivity.activityEndTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">参与人数：</label>
                <div class="col-sm-8">
                    <input id="activityPeopleNum" name="activityPeopleNum" th:field="*{activityPeopleNum}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">报名费用：</label>
                <div class="col-sm-8">
                    <input id="activityCost" name="activityCost" th:field="*{activityCost}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">活动简介：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{activityContent}">
                    <div class="summernote" id="activityContent"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">关键词：</label>
                <div class="col-sm-8">
                    <input id="activityKeyword" name="activityKeyword" th:field="*{activityKeyword}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片1：</label>
                <div class="col-sm-8">
                    <input id="activityImgOne" name="activityImgOne" th:field="*{activityImgOne}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片2：</label>
                <div class="col-sm-8">
                    <input id="activityImgTwo" name="activityImgTwo" th:field="*{activityImgTwo}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片3：</label>
                <div class="col-sm-8">
                    <input id="activityImgThree" name="activityImgThree" th:field="*{activityImgThree}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片4：</label>
                <div class="col-sm-8">
                    <input id="activityImgFour" name="activityImgFour" th:field="*{activityImgFour}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">主题图片：</label>
                <div class="col-sm-8">
                    <input id="themeImg" name="themeImg" th:field="*{themeImg}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/activity";
        $("#form-activity-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-activity-edit').serialize());
            }
        }

        $("input[name='activityStartTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='activityEndTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>